package 并发编程15.线程池;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 当创建的时候需要指定线程池最大数目，否则将任务提交到池队列中
 *
 * @author idea
 * @data 2019/2/22
 */
public class newFixedThreadPoolDemo {

    public static void main(String[] args) {
        ExecutorService fixedService=Executors.newFixedThreadPool(2);
        for(int i=0;i<10;i++){
            int index=i;
            fixedService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(""+Thread.currentThread().getName()+":"+index);
                }
            });
        }
    }
}
